package com.mj.util;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.core.io.Resource;
import org.springframework.stereotype.Component;

/**
 * 通过实现ApplicationContextAware
 * 获取初始bean
 * 
 * @author majie
 *
 */
@Component	//注入spring
public class SpringUtil implements ApplicationContextAware {

	private static ApplicationContext applicationContext;

	public void setApplicationContext(ApplicationContext context) throws BeansException {
		SpringUtil.applicationContext = context;
	}

	public static Object getBean(String name) {
		return applicationContext.getBean(name);
	}

	public static Resource getResource(String name) {
		return applicationContext.getResource(name);
	}
}
